home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Tools / TASM V5 / TASMDOC.PAK / MAKE.TXT next >
Text File  |  1996-02-21  |  34KB  |  1,073 lines

  1. /*************************************************************************/
  2.                                   MAKE.TXT
  3.                                TURBO ASSEMBLER
  4.  
  5. This file contains details on using MAKE and MAKER with TASM.
  6. --------------------------------------------------------------------
  7.                         TABLE OF CONTENTS
  8.                         - - - - - - - - -
  9.    MAKE basics
  10.       BUILTINS.MAK
  11.       Using TOUCH.EXE
  12.       MAKE options
  13.          Setting options on as defaults
  14.          Compatibility with Microsoft's NMAKE
  15.    Using makefiles
  16.       Symbolic targets
  17.          Rules for symbolic targets
  18.    Explicit and implicit rules
  19.       Explicit rule syntax
  20.          Single targets with multiple rules
  21.       Implicit rule syntax
  22.          Explicit rules with implicit commands
  23.       Commands syntax
  24.          Command prefixes
  25.          Using @
  26.          Using -num and -
  27.          Using &
  28.          Command operators
  29.          Debugging with temporary files
  30.    Using MAKE macros
  31.       Defining macros
  32.       Using a macro
  33.       String substitutions in macros
  34.       Default MAKE macros
  35.       Modifying default macros
  36.    Using MAKE directives
  37.       .autodepend
  38.       !error
  39.          Summing up error-checking controls
  40.       !if and other conditional directives
  41.       !include
  42.       !message
  43.       .path.ext
  44.       .precious
  45.       .suffixes
  46.       !undef
  47.       Using macros in directives
  48. --------------------------------------------------------------------
  49.  
  50. MAKE.EXE is a command-line project-manager utility that helps you
  51. quickly compile only those files in a project that have changed since
  52. the last compilation. (MAKER is a real-mode version of MAKE.)
  53.  
  54. This chapter covers the following topics:
  55.   o  MAKE basics
  56.   o  Makefile contents
  57.   o  Using explicit and implicit rules
  58.   o  Using MAKE macros
  59.   o  Using MAKE directives
  60.  
  61.  
  62. MAKE basics
  63. ===========
  64. MAKE uses rules from a text file (MAKEFILE or MAKEFILE.MAK by default)
  65. to determine which files to build and how to build them. For example,
  66. you can get MAKE to compile an .EXE file if the date-time stamps for
  67. the .CPP files that contain the code for the .EXE are more recent than
  68. the .EXE itself. MAKE is very useful when you build a program from
  69. more than one file because MAKE will recompile only the files that you
  70. modified since the last compile.
  71.  
  72. Two types of rules (explicit and implicit) tell MAKE what files depend
  73. on each other. MAKE then compares the date-time stamp of the files in
  74. a rule and determines if it should execute a command (the commands
  75. usually tell MAKE which files to recompile or link, but the commands
  76. can be nearly any operating system command).
  77.  
  78. The general syntax for MAKE is:
  79.  
  80.     MAKE [options...] [targets[s]]
  81.  
  82. (To get command-line help for MAKE, type MAKE -? or MAKE -h.)
  83.  
  84. "Options" are MAKE options that control how MAKE works, and
  85. "targets" are the names of the files in a makefile that you want MAKE to
  86. build. Options are separated from MAKE by a single space. Options and
  87. targets are also separated by spaces.
  88.  
  89. If you type MAKE at the command prompt, MAKE performs the following
  90. default tasks:
  91.  
  92. To place MAKE instructions in a file other than MAKEFILE, see
  93. the section titled "MAKE options."
  94.  
  95. MAKE looks in the current directory for a file called BUILTINS.MAK
  96. (this file contains rules MAKE always follows unless you use the -r option).
  97. If it can't find the file in the current directory, it looks in the
  98. directory where MAKE.EXE is stored. After loading BUILTINS.MAK, MAKE looks
  99. for a file called MAKEFILE or MAKEFILE.MAK. If MAKE can't find any of these
  100. files, it gives you an error message.
  101.  
  102. When MAKE finds a makefile, it tries to build only the first target
  103. file in the makefile (although the first target can force other
  104. targets to be built). MAKE checks the time and date of the dependent
  105. files for the first target. If the dependent files are more recent
  106. than the target file, MAKE executes the target commands, which update
  107. the target. See the section called "Using makefiles" for more
  108. information on instructions in makefiles.
  109.  
  110.  1) If a dependent file for the first target appears as a target elsewhere
  111.     in the makefile, MAKE checks its dependencies and builds it before
  112.     building the first target. This chain reaction is called linked
  113.     dependency.
  114.  
  115.  2) If the MAKE build process fails, MAKE deletes the target file it was
  116.     building. To get MAKE to keep a target when a build fails, see the
  117.     .precious directive.
  118.  
  119. You can stop MAKE by using <Ctrl><Break> or <Ctrl><C>.
  120.  
  121.  
  122. BUILTINS.MAK
  123. ------------
  124. BUILTINS.MAK contains standard rules and macros that MAKE uses before
  125. it uses a makefile (you can use the -r option to tell MAKE to ignore
  126. BUILTINS.MAK). Use BUILTINS.MAK for instructions or macros you want
  127. executed each time you use MAKE. Here's the default text of
  128. BUILTINS.MAK:
  129.  
  130. #
  131. # Borland C++ - (C) Copyright 1993 by Borland International
  132. #
  133.  
  134. # default is to target 32BIT
  135. # pass -DWIN16 to make to target 16BIT
  136.  
  137. !if !$d(WIN16)
  138. CC       = bcc32
  139. RC       = brcc32
  140. AS       = tasm32
  141. !else
  142. CC       = bcc
  143. RC       = brcc
  144. AS       = tasm
  145. !endif
  146.  
  147. .asm.obj:
  148.       $(AS) $(AFLAGS) $&.asm
  149.  
  150. .c.exe:
  151.       $(CC) $(CFLAGS) $&.c
  152.  
  153. .c.obj:
  154.       $(CC) $(CFLAGS) /c $&.c
  155.  
  156. .cpp.exe:
  157.       $(CC) $(CFLAGS) $&.cpp
  158.  
  159. .cpp.obj:
  160.       $(CC) $(CPPFLAGS) /c $&.cpp
  161.  
  162. .rc.res:
  163.       $(RC) $(RFLAGS) /r $&
  164.  
  165. .SUFFIXES: .exe .obj .asm .c .res .rc
  166.  
  167. !if !$d(BCEXAMPLEDIR)
  168. BCEXAMPLEDIR = $(MAKEDIR)\..\EXAMPLES
  169. !endif
  170.  
  171.  
  172. Using TOUCH.EXE
  173. ---------------
  174. Sometimes you'll want to force a target file to be recompiled or
  175. rebuilt even though you haven't changed it. One way to do this is to
  176. use the TOUCH utility. TOUCH changes the date and time of one or more
  177. files to the current date and time, making it "newer" than the files
  178. that depend on it.
  179.  
  180. You can force MAKE to rebuild a target file by touching one of the
  181. files that target depends on. To touch a file (or files), type the
  182. following at the command prompt:
  183.  
  184.     touch filename [filename...]
  185.  
  186. TOUCH updates the file's creation date and time.
  187.  
  188. Before you use TOUCH, make sure your system's internal clock is set
  189. correctly. If it isn't, TOUCH and MAKE won't work properly.
  190.  
  191.  
  192. MAKE options
  193. ------------
  194. Command-line options control MAKE behavior. Options are
  195. case-sensitive. Type options with either a preceding - or /. For
  196. example, to use a file called PROJECTA.MAK as the makefile, type MAKE
  197. -fPROJECTA.MAK (a space after -f is optional). Many of the
  198. command-line options have equivalent directives that are used in the
  199. makefile. The following table describes MAKE's command-line options.
  200.  
  201.  
  202. Option        Description
  203. ------        -----------
  204. -h or -?    Displays MAKE options and shows defaults with
  205.         a trailing plus sign.
  206.  
  207. -B        Builds all targets regardless of file dates.
  208.  
  209. -D<macro>    Defines <macro> as a single character, causing
  210.         an expression <!ifdef macro> written in the
  211.         makefile to return true.
  212.  
  213. [-D]<macro>=[string]    Defines <macro> as "string." If "string"
  214.             contains any spaces or tabs, enclose "string"
  215.             in quotation marks. The -D is optional.
  216.  
  217. -I<directory>    Searches for include files in the current
  218.         directory first, then in <directory>.
  219.  
  220. -K        Keeps temporary files that MAKE creates (MAKE
  221.         usually deletes them).
  222.  
  223. -N        Executes MAKE like Microsoft's NMAKE (see the
  224.         section following this table for more
  225.         information).
  226.  
  227. -U<macro>    Undefines previous definitions of <macro>.
  228.  
  229. -W        Writes the current specified non-string
  230.         options to MAKE.EXE making them defaults.
  231.  
  232. -f<filename>    Uses <filename> or <filename>.MAK instead of
  233.         MAKEFILE (space after -f is optional).
  234.  
  235. -a        Checks dependencies of include files and
  236.         nested include files associated with .OBJ
  237.         files and updates the .OBJ if the .H file
  238.         changed. See also -c.
  239.  
  240. -c        Caches autodependency information, which can
  241.         improve MAKE's speed. Use with -a; don't use
  242.         if MAKE changes include files (such as using
  243.         TOUCH from a makefile or creating header or
  244.         include files during the MAKE process).
  245.  
  246. -d<directory>    Used with -S to specify the drive and
  247.         directory MAKE uses when it swaps out of
  248.         memory. The option is ineffective when used
  249.         with the MAKER.
  250.  
  251. -e        Ignores a macro if its name is the same as an
  252.         environment variable (MAKE uses the
  253.         environment variable instead of the macro).
  254.  
  255. -i        Ignores the exit status of all programs run
  256.         from MAKE and continues the build process.
  257.  
  258. -m        Displays the date and time stamp of each file
  259.         as MAKE processes it.
  260.  
  261. -n        Prints the commands but doesn't actually
  262.         perform them, which is helpful for debugging
  263.         a makefile.
  264.  
  265. -p        Displays all macro definitions and implicit
  266.         rules before executing the makefile.
  267.  
  268. -q        Returns 0 if the target is up-to-date and
  269.         nonzero if is is not (for use with batch
  270.         files).
  271.  
  272. -r        Ignores any rules defined in BUILTINS.MAK.
  273.  
  274. -s        Suppresses onscreen command display.
  275.  
  276. -S        Swaps MAKER out of memory while commands are
  277.         executed, reducing memory overhead and
  278.         allowing compilation of large modules. This
  279.         option has no effect on MAKER.
  280.  
  281. -W        Sets MAKE defaults.
  282.  
  283.  
  284. Setting options on as defaults
  285. - - - - - - - - - - - - - - - -
  286. The -W option lets you set some MAKE options on as defaults so that
  287. each time you use MAKE, those options are used. To set MAKE options,
  288. type:
  289.  
  290.     make  -option[-]  [-option][-]  . . . -W
  291.  
  292. For example, you could type "MAKE -m -W" to always view file dates and
  293. times. Type "MAKE -m- -W" to turn off the default option. When MAKE asks
  294. you to write changes to MAKE.EXE, type Y.
  295.  
  296. The -W option doesn't work when the DOS Share program
  297. is running. The message "Fatal: unable to open file MAKE.EXE" is
  298. displayed. The -W option doesn't work with the following MAKE options:
  299.   o  -D<macro>
  300.   o  -D<macro>=<string>
  301.   o  -d<directory>
  302.   o  -U<symbol>
  303.   o  -f<filename>
  304.   o  -? or -h
  305.   o  -I<directory>
  306.  
  307.  
  308. Compatibility with Microsoft's NMAKE
  309. - - - - - - - - - - - - - - - - - - -
  310. Use the -N option if you want to use makefiles that were originally
  311. created for Microsoft's NMAKE. The following changes occur when you
  312. use -N:
  313.  
  314.   MAKE interprets the << operator like the && operator: temporary files
  315.   are used as response files, then deleted. To keep a file, either use
  316.   the -K command-line option or use KEEP in the makefile.
  317.  
  318.     <<TEMPFILE.TXT!
  319.     text
  320.  
  321.     !KEEP
  322.  
  323.   If you don't want to keep a temporary file, type NOKEEP or type
  324.   only the temporary file name. If you use NOKEEP with a temporary
  325.   file, then use the -K option with MAKE, MAKE deletes the temporary file.
  326.  
  327.   o  The $d macro is treated differently. Use "!ifdef" or "!ifndef" instead.
  328.  
  329.   o  Macros that return paths won't return the last \. For example, if
  330.      $(<D) normally returns C:\CPP\, the -N option makes it return C:\CPP.
  331.  
  332.   o  Unless there's a matching .suffixes directive, MAKE searches rules
  333.      from bottom to top of the makefile.
  334.  
  335.   o  The $* macro always expands to the target name instead of the
  336.      dependent in an implicit rule.
  337.  
  338.  
  339. Using makefiles
  340. ===============
  341. A makefile is an ASCII file of instructions for MAKE.EXE. MAKE assumes
  342. your makefile is called MAKEFILE or MAKEFILE.MAK unless you use the -f
  343. option.
  344.  
  345. MAKE either builds targets you specify at the MAKE command line or it
  346. builds only the first target it finds in the makefile (to build more
  347. than one target, see the section "Symbolic targets.") Makefiles can
  348. contain:
  349.   o  Comments
  350.   o  Explicit rules
  351.   o  Implicit rules
  352.   o  Macros
  353.   o  Directives
  354.  
  355.  
  356. Symbolic targets
  357. ----------------
  358. A symbolic target forces MAKE to build multiple targets in a makefile
  359. (you don't need to rely on linked dependencies). The dependency line
  360. lists all the targets you want to build. You don't type any commands
  361. for a symbolic target.
  362.  
  363. In the following makefile, the symbolic target "allFiles" builds both
  364. FILE1.EXE and FILE2.EXE:
  365.  
  366.   allFiles: file1.exe file2.exe     #Note this target has no commands.
  367.   file1.exe: file1.obj
  368.       bcc file1.obj
  369.   file2.exe: file2.obj
  370.       bcc file2.obj
  371.  
  372.  
  373. Rules for symbolic targets
  374. - - - - - - - - - - - - - -
  375. Observe the following rules with symbolic targets:
  376.  
  377.   o  Symbolic targets don't need a command line.
  378.  
  379.   o  Give your symbolic target a unique name; it can't be the name of a
  380.      file in your current directory.
  381.  
  382.   o  Name symbolic targets according to the operating system rules for
  383.      naming files.
  384.  
  385.  
  386. Explicit and implicit rules
  387. ===========================
  388. The explicit and implicit rules that instruct MAKE are generally
  389. defined as follows:
  390.  
  391.   o  Explicit rules give MAKE instructions for specific files.
  392.  
  393.   o  Implicit rules give general instructions that MAKE follows when it
  394.      can't find an explicit rule.
  395.  
  396. Rules follow this general format:
  397.  
  398.   Dependency line
  399.     Commands
  400.  
  401. The dependency line is different for explicit and implicit rules, but
  402. the commands are the same.
  403.  
  404. MAKE supports multiple rules for one target. You can add dependent
  405. files after the first explicit rule, but only one should contain a
  406. command line. For example:
  407.  
  408.   Target1: dependent1 dep2 dep3 dep4 dep5
  409.   Target1: dep6 dep7 dep8
  410.     bcc -c $**
  411.  
  412.  
  413. Explicit rule syntax
  414. --------------------
  415. Explicit rules are instructions to MAKE that specify exact file names.
  416. The explicit rule names one or more targets followed by one or two
  417. colons. One colon means one rule is written for the target; two colons
  418. mean that two or more rules are written for the target.
  419.  
  420. Explicit rules follow this syntax:
  421.  
  422.   target [target...]:[:][{path}] [dependent[s]...]
  423.     [commands]
  424.  
  425.  o  target    The name and extension of the file to be updated
  426.         ("target" must be at the start of the line--no spaces or
  427.         tabs are allowed). One or more targets must be
  428.         separated by spaces or tabs. Don't use a target's name
  429.         more than once in the target position of an explicit
  430.         rule in a makefile.
  431.  
  432.  o  path    A list of directories, separated by semicolons and
  433.         enclosed in braces, that points to the dependent files.
  434.  
  435.  o  dependent    The file (or files) whose date and time MAKE checks to
  436.         see if it is newer than "target" (dependent must be
  437.         preceded by a space). If a dependent file also appears
  438.         in the makefile as a target, MAKE updates or creates
  439.         the target file before using it as a dependent for
  440.         another target.
  441.  
  442.  o  commands    Any operating system command. Multiple commands are
  443.         allowed in a rule. Commands must be indented by at
  444.         least one space or tab.
  445.  
  446. If the dependency or command continues on to the next line, use the
  447. backslash (\) at the end of the line after a target or a dependent
  448. file name. For example:
  449.  
  450.   MYSOURCE.EXE: FILE1.OBJ\
  451.               FILE2.OBJ\
  452.               FILE3.OBJ
  453.      bcc file1.obj file2.obj file3.obj
  454.  
  455.  
  456. Single targets with multiple rules
  457. - - - - - - - - - - - - - - - - - -
  458. A single target can have more than one explicit rule. You must use the
  459. double colon (::) after the target name to tell MAKE to expect multiple
  460. explicit rules. The following example shows how one target can have
  461. multiple rules and commands:
  462.  
  463.   .cpp.obj:
  464.     bcc -c -ncobj $<
  465.  
  466.   .asm.obj:
  467.     tasm  /mx $<, asmobj\\
  468.  
  469.   mylib.lib :: f1.obj f2.obj
  470.     echo Adding C files
  471.     tlib mylib -+cobj\f1 -+cobj\f2
  472.  
  473.   mylib.lib :: f3.obj f4.obj
  474.     echo Adding ASM files
  475.     tlib mylib -+asmobj\f3 -+asmobj\f4
  476.  
  477.  
  478. Implicit rule syntax
  479. --------------------
  480. An implicit rule starts with either a path or a period and implies a
  481. target-dependent file relationship. Its main components are file
  482. extensions separated by periods. The first extension belongs to the
  483. dependent, the second to the target.
  484.  
  485. If implicit dependents are out-of-date with respect to the target or
  486. if they don't exist, MAKE executes the commands associated with the
  487. rule. MAKE updates explicit dependents before it updates implicit
  488. dependents.
  489.  
  490. Implicit rules follow this basic syntax:
  491.  
  492.   [{source_dirs}].source_ext[{target_dirs}].target_ext:
  493.      [commands]
  494.  
  495.   o  {source_dirs}    The directory of the dependent files.
  496.             Separate multiple directories with a semicolon.
  497.  
  498.   o  .source_ext    The dependent file-name extension.
  499.  
  500.   o  {target_dirs}    The directory of the target (executable) files.
  501.             Separate multiple directories with a semicolon.
  502.  
  503.   o  .target_ext    The target file-name extension. Macros are allowed.
  504.  
  505.   o  :            Marks the end of the dependency line.
  506.  
  507.   o  commands        Any operating system command. Multiple commands
  508.             are allowed. Commands must be indented by one
  509.             space or tab.
  510.  
  511. If two implicit rules match a target extension but no dependent
  512. exists, MAKE uses the implicit rule whose dependent's extension
  513. appears first in the .SUFFIXES list.
  514.  
  515.  
  516. Explicit rules with implicit commands
  517. - - - - - - - - - - - - - - - - - - -
  518. A target in an explicit rule can get its command line from an implicit
  519. rule. The following example shows an implicit rule and an explicit
  520. rule without a command line:
  521.  
  522.   .c.obj:
  523.      bcc -c $<     #This command uses a macro $< described later.
  524.  
  525.   myprog.obj:      #This explicit rule uses the command: bcc -c myprog.c
  526.  
  527. The implicit rule command tells MAKE to compile MYPROG.C (the macro $<
  528. replaces the name "myprog.obj" with "myprog.c").
  529.  
  530.  
  531. Commands syntax
  532. ---------------
  533. Commands can be any operating system command, but they can also
  534. include MAKE macros, directives, and special operators that operating
  535. systems can't recognize (note that | can't be used in commands). Here
  536. are some sample commands:
  537.  
  538.   cd..
  539.  
  540.   bcc -c mysource.c
  541.  
  542.   COPY *.OBJ C:\PROJECTA
  543.  
  544.   bcc -c $(SOURCE)     #Macros are explained later in the chapter.
  545.  
  546. Commands follow this general syntax:
  547.  
  548.     [prefix...] commands
  549.  
  550.  
  551. Command prefixes
  552. - - - - - - - - -
  553. Commands in both implicit and explicit rules can have prefixes that
  554. modify how MAKE treats the commands. The following table lists the prefixes
  555. you can use in makefiles:
  556.  
  557. Option        Description
  558. ------        -----------
  559. @        Don't display command while it's being executed.
  560.  
  561. -<num>        Stop processing commands in the makefile when the
  562.         exit code returned from command exceeds <num>.
  563.         Normally, MAKE aborts if the exit code is nonzero.
  564.         No white space is allowed between - and <num>.
  565.  
  566. -        Continue processing commands in the makefile,
  567.         regardless of the exit code returned by them.
  568.  
  569. &        Expand either the macro $**, which represents all
  570.         dependent files, or the macro $?, which represents
  571.         all dependent files stamped later than the target.
  572.         Execute the command once for each dependent file
  573.         in the expanded macro.
  574.  
  575.  
  576. Using @
  577. - - - -
  578. The following command uses the modifier @, which prevents the command
  579. from displaying onscreen when MAKE executes it.
  580.  
  581.   diff.exe : diff.obj
  582.     @bcc diff.obj
  583.  
  584.  
  585. Using -num and -
  586. - - - - - - - - -
  587. The "-num" and "-" modifiers control MAKE processing under error
  588. conditions. You can choose to continue with the MAKE process if an
  589. error occurs or only if the errors exceed a given number.
  590.  
  591. In the following example, MAKE continues processing if BCC isn't run
  592. successfully:
  593.  
  594.   target.exe : target.obj
  595.   target.obj : target.cpp
  596.     bcc -c target.cpp
  597.  
  598.  
  599. Using &
  600. - - - -
  601. The & modifier issues a command once for each dependent file. It is
  602. especially useful for commands that don't take a list of files as
  603. parameters. For example,
  604.  
  605.   copyall : file1.cpp file2.cpp
  606.     © $** c:\temp
  607.  
  608. results in COPY being invoked twice as follows:
  609.  
  610.   copy file1.cpp c:\temp
  611.   copy file2.cpp c:\temp
  612.  
  613. Without the & modifier, COPY would be called only once.
  614.  
  615. Command operators
  616. - - - - - - - - -
  617. You can use any operating system command in a MAKE commands section.
  618. MAKE uses the normal operators (such as +, -, and so on), but it also
  619. has other operators you can use.
  620.  
  621. Operator    Description
  622. --------    -----------
  623. <        Take the input for use by "command" from
  624.         "file" rather than from standard input.
  625.  
  626. >        Send the output from "command" to "file".
  627.  
  628. >>        Append the output from "command" to "file".
  629.  
  630. <<        Create a temporary, inline file and use
  631.         its contents as standard input to
  632.         "command".
  633.  
  634. &&        Create a temporary file and insert its
  635.         name in the makefile.
  636.  
  637. delimiter    Any character other than # and \ used
  638.         with << and && as a starting and ending
  639.         delimiter for a temporary file. Any
  640.         characters on the same line and
  641.         immediately following the starting
  642.         delimiter are ignored. The closing
  643.         "delimiter" must be written on a line by
  644.         itself.
  645.  
  646.  
  647. Debugging with temporary files
  648. - - - - - - - - - - - - - - - -
  649. Temporary files can help you debug a command set by placing the actual
  650. commands MAKE executes into the temporary file. Temporary file names
  651. start at MAKE0000.@@@, where the 0000 increments for each temporary
  652. file you keep. You must place delimiters after && and at the end of
  653. what you want sent to the temporary file (! is a good delimiter).
  654.  
  655. The following example shows && instructing MAKE to create a file of
  656. the input to TLINK.
  657.  
  658.   prog.exe: A.obj B.obj
  659.      TLINK /c &&!
  660.      c0s.obj $**
  661.      prog.exe
  662.      prog.map
  663.      maths.lib cs.lib
  664.      !
  665.  
  666. The response file created by && contains these instructions:
  667.  
  668.      c0s.obj a.obj b.obj
  669.      prog.exe
  670.      prog.map
  671.      maths.lib cs.lib
  672.  
  673.  
  674. Using MAKE macros
  675. =================
  676. A MAKE macro is a string that is expanded (used) wherever the macro is
  677. called in a makefile. Macros let you create template makefiles that
  678. you can change to suit different projects. For example, to define a
  679. macro called LIBNAME that represents the string "mylib.lib," type
  680. "LIBNAME = mylib.lib". When MAKE encounters the macro "$(LIBNAME)", it
  681. uses the string "mylib.lib".
  682.  
  683. If MAKE finds an undefined macro in a makefile, it looks for an
  684. operating-system environment variable of that name (usually defined
  685. with SET) and uses its definition as the expansion text. For example,
  686. if you wrote "$(path)" in a makefile and never defined "path", MAKE would
  687. use the text you defined for PATH in your AUTOEXEC.BAT. (See the
  688. manuals for your operating system for information on defining
  689. environment variables.)
  690.  
  691.  
  692. Defining macros
  693. ---------------
  694. The general syntax for defining a macro in a makefile is:
  695.  
  696.     MacroName = expansion_text
  697.  
  698.   o  "MacroName" is case-sensitive and is limited to 512 characters.
  699.  
  700.   o  "expansion_text" is limited to 4096 characters consisting of
  701.      alpha-numeric characters, punc-tuation, and white space.
  702.  
  703. Each macro must be on a separate line in a makefile. Macros are
  704. usually put at the top of the makefile. If MAKE finds more than one
  705. definition for a "macroName", the new definition replaces the old one.
  706.  
  707. Macros can also be defined using the command-line option -D. More than
  708. one macro can be defined by separating them with spaces. The following
  709. examples show macros defined at the command line:
  710.  
  711.   make -Dsourcedir=c:\projecta
  712.   make command="bcc -c"
  713.   make command=bcc option=-c
  714.  
  715. The following differences in syntax exist between macros entered on
  716. the command line and macros written in a makefile.
  717.  
  718.             Makefile    Command line
  719.             --------    ------------
  720. Spaces allowed before
  721. and after =        Yes        No
  722.  
  723. Space allowed before
  724. macroName        No        Yes
  725.  
  726.  
  727. Using a macro
  728. -------------
  729. To use a macro in a makefile, type "$(MacroName)" where MacroName is the
  730. name of a defined macro. You can use braces {} and parentheses () to
  731.  
  732. MAKE expands macros at various times depending on where they appear in
  733. the makefile:
  734.  
  735.   o  Nested macros are expanded when the outer macro is invoked.
  736.  
  737.   o  Macros in rules and directives are expanded when MAKE first looks at
  738.      the makefile.
  739.  
  740.   o  Macros in commands are expanded when the command is executed.
  741.  
  742.  
  743. String substitutions in macros
  744. ------------------------------
  745. MAKE lets you temporarily substitute characters in a previously
  746. defined macro.  For example, if you defined a macro called SOURCE as
  747. "SOURCE = f1.cpp f2.cpp f3.cpp", you could substitute the characters
  748. .OBJ for the characters .CPP by using "$(SOURCE:.CPP=.OBJ)". The
  749. substitution doesn't redefine the macro.
  750.  
  751. Rules for macro substitution:
  752.  
  753.   o  Syntax: $(MacroName:original_text=new_text)
  754.  
  755.   o  No whitespace before or after the colon.
  756.  
  757.   o  Characters in "original_text" must exactly match the characters in the
  758.      macro definition; this text is case-sensitive.
  759.  
  760. MAKE now lets you use macros within substitution macros. For example:
  761.  
  762.   MYEXT=.C
  763.   SOURCE=f1.cpp f2.cpp f3.cpp
  764.   $(SOURCE:.cpp=$(MYEXT))         #Changes f1.cpp to f1.C, etc.
  765.  
  766.  
  767. Default MAKE macros
  768. -------------------
  769. MAKE contains several default macros you can use in your makefiles.
  770. The following table lists the macro definition and what it expands to
  771. in explicit and implicit rules.
  772.  
  773. Macro    Expands in implicit:    Expands in explicit:    Example
  774. -----    --------------------    --------------------    -------
  775. $*    path\dependent file    path\target file    C:\PROJ\MYTARGET
  776.  
  777. $<    path\dependent file+ext    path\target file+ext    C:\PROJ\MYTARGET.OBJ
  778.  
  779. $:    path for dependents    path for target        C:\PROJ
  780.  
  781. $.    dependent file+ext    target file + ext    MYSOURCE.C
  782.  
  783. $&    dependent file       target file         MYSOURCE
  784.  
  785. $@    path\target file+ext    path\target file+ext    C:\PROJ\MYSOURCE.C
  786.  
  787. $**    path\dependent file+ext    all dependents file+ext    F1.CPP F2.CPP F3.CPP
  788.  
  789. $?    path\dependent file+ext    old dependents        FILE1.CPP
  790.  
  791.  
  792. Macro        Expands to:    Comment
  793. -----        -----------    -------
  794. __MSDOS__    1        If running under DOS.
  795.  
  796. __MAKE__    0x0370        MAKE's hex version number.
  797.  
  798. MAKE        make        MAKE's executable file name.
  799.  
  800. MAKEFLAGS    options        The options typed at the
  801.                 command line.
  802.  
  803. MAKEDIR        directory    Directory where MAKE.EXE is
  804.                 located.
  805.  
  806.  
  807. Modifying default macros
  808. ------------------------
  809. When the default macros listed in the preceding table doesn't give you
  810. the exact string you want, macro modifiers let you extract parts of
  811. the string to suit your purpose.
  812.  
  813. To modify a default macro, use this syntax:
  814.  
  815.     $(MacroName [modifier])
  816.  
  817. The following table lists macro modifiers and provides examples of
  818. their use.
  819.  
  820. Modifier    Part of file name expanded    Example    Result
  821. --------    --------------------------    --------------
  822. D        Drive and directory        $(<D)    C:\PROJECTA\
  823.  
  824. F        Base and extension        $(<F)    MYSOURCE.C
  825.  
  826. B        Base only            $(<B)    MYSOURCE
  827.  
  828. R        Drive, directory, and base    $(<R)    C:\PROJECTA\MYSOURCE
  829.  
  830.  
  831. Using MAKE directives
  832. =====================
  833. MAKE directives resemble directives in languages such as C and Pascal,
  834. and perform various control functions, such as displaying commands
  835. onscreen before executing them. MAKE directives begin either with an
  836. exclamation point or a period. The following table lists MAKE directives
  837. and their corresponding command-line options (directives override
  838. command-line options). Each directive is described in more detail
  839. following the table.
  840.  
  841. Directive    Option        Description
  842. ---------    ------        -----------
  843. .autodepend    -a        Turns on autodependency checking.
  844.  
  845. !elif                Acts like a C "else if".
  846.  
  847. !else                Acts like a C "else".
  848.  
  849. !endif                Ends an "!if", "!ifdef", or "!ifndef"
  850.                 statement.
  851.  
  852. !error                Stops MAKE and prints an error message.
  853.  
  854. !if                Begins a conditional statement.
  855.  
  856. !ifdef                If defined that acts like a C "ifdef", but
  857.                 with macros rather than "#define" directives.
  858.  
  859. !ifndef                If not defined.
  860.  
  861. .ignore        -i        MAKE ignores the return value of a command.
  862.  
  863. !include            Specifies a file to include in the makefile.
  864.  
  865. !message            Lets you print a message from a makefile.
  866.  
  867. .noautodepend    -a-        Turns off autodependency checking.
  868.  
  869. .noIgnore    -i-        Turns off ".Ignore".
  870.  
  871. .nosilent    -s-        Displays commands before MAKE executes them.
  872.  
  873. .noswap        -S-        Tells MAKE not to swap itself out of memory
  874.                 before executing a command.
  875.  
  876. .path.ext            Tells MAKE to search for files with the
  877.                 extension .ext in path directories.
  878.  
  879. .precious            Saves the target or targets even if the
  880.                 build fails.
  881.  
  882. .silent        -s        Executes without printing the commands.
  883.  
  884. .suffixes            Determines the implicit rule for ambiguous
  885.                 dependencies.
  886.  
  887. .swap        -S        Tells MAKE to swap itself out of memory
  888.                 before executing a command.
  889.  
  890. !undef                Clears the definition of a macro.
  891.  
  892.  
  893. .autodepend
  894. -----------
  895. Autodependencies occur in .OBJ files that have corresponding .CPP, .C,
  896. or .ASM files. With ".autodepend" on, MAKE compares the dates and times
  897. of all the files used to build the .OBJ. If the dates and times of the
  898. files used to build the .OBJ are different from the date-time stamp of
  899. the.OBJ file, the .OBJ file is recompiled. You can use ".autodepend" or
  900. -a in place of linked dependencies.
  901.  
  902.  
  903. !error
  904. ------
  905. This is the syntax of the !error directive:
  906.  
  907.   !error message
  908.  
  909. MAKE stops processing and prints the following string when it
  910. encounters this directive:
  911.  
  912.   Fatal makefile exit code: Error directive: message
  913.  
  914. Embed !error in conditional statements to abort processing and print
  915. an error message, as shown in the following example:
  916.  
  917.   !if !$d(MYMACRO)
  918.   #if MYMACRO isn't defined
  919.   !error MYMACRO isn't defined
  920.   !endif
  921.  
  922. If MYMACRO in the example isn't defined, MAKE prints the following
  923. message:
  924.  
  925.   Fatal makefile 4: Error directive: MYMACRO isn't defined
  926.  
  927.  
  928. Summing up error-checking controls
  929. - - - - - - - - - - - - - - - - - -
  930. Four different controls turn off error checking:
  931.  
  932.   o  The .ignore directive turns off error checking for a selected portion
  933.      of the makefile.
  934.  
  935.   o  The -i command-line option turns off error checking for the entire
  936.      makefile.
  937.  
  938.   o  The -num command operator, which is entered as part of a rule, turns
  939.      off error checking for the related command if the exit code exceeds
  940.      the specified number.
  941.  
  942.   o  The - command operator turns off error checking for the related
  943.      command regardless of the exit code.
  944.  
  945.  
  946. !if and other conditional directives
  947. ------------------------------------
  948. The !if directive works like C if statements. The syntax of !if and the
  949. other conditional directives resembles compiler conditionals.
  950.  
  951.  
  952. !include
  953. --------
  954. This directive is like the #include preprocessor directive for the C
  955. or C++ language--it lets you include the text of another file in the
  956. makefile:
  957.  
  958.   !include <filename>
  959.  
  960. You can enclose <filename> in quotation marks ("") or angle brackets
  961. (<>) and nest directives to unlimited depth, but writing duplicate
  962. !include directives in a makefile isn't permitted--you'll get the
  963. error message "cycle in the include file".
  964.  
  965. Rules, commands, or directives must be complete within a single source
  966. file; you can't start a command in an !include file, then finish it in
  967. the makefile.
  968.  
  969. MAKE searches for !include files in the current directory unless
  970. you've specified another directory with the -I option.
  971.  
  972.  
  973. !message
  974. --------
  975. The !message directive lets you send messages to the screen from a
  976. makefile. You can use these messages to help debug a makefile that
  977. isn't working the way you'd like it to. For example, if you're having
  978. trouble with a macro definition, you could put this line in your
  979. makefile:
  980.  
  981.   !message The macro is defined here as: $(<MacroName>)
  982.  
  983. When MAKE interprets this line, it will print onscreen "The macro is
  984. defined here as: .CPP", if the macro expands to .CPP at that line.
  985. Using a series of !message directives, you can debug your makefiles.
  986.  
  987.  
  988. .path.ext
  989. ---------
  990. The .path.ext directive tells MAKE where to look for files with a
  991. certain extension. The following example tells MAKE to look for files
  992. with the .c extension in C:\SOURCE or C:\CFILES and to look for files
  993. with the .obj extension in C:\OBJS.
  994.  
  995.   .path.c = C:\CSOURCE;C:\CFILES
  996.   .path.obj = C:\OBJS
  997.  
  998.  
  999. .precious
  1000. ---------
  1001. If a MAKE build fails, MAKE deletes the target file. The .precious
  1002. directive prevents the file deletion, which is desired for certain
  1003. kinds of targets such as libraries. When a build fails to add a module
  1004. to a library, you don't want the library to be deleted.
  1005.  
  1006. The syntax for .precious is:
  1007.  
  1008.   .precious: target [target] . . . [target]
  1009.  
  1010.  
  1011. .suffixes
  1012. ---------
  1013. The .suffixes directive tells MAKE the order (by file extensions) for
  1014. building implicit rules.
  1015.  
  1016. The syntax of the .suffixes directive is:
  1017.  
  1018.   .suffixes: .ext [.ext]  [.ext] . . . [.ext]
  1019.  
  1020. .ext represents the dependent file extension in implicit rules. For
  1021. example, you could include the line ".suffixes: .asm .c .cpp" to tell
  1022. MAKE to interpret implicit rules beginning with the ones dependent on
  1023. .ASM files, then .C files, then .CPP files, regardless of what order
  1024. they appear in the makefile.
  1025.  
  1026. The following example shows a makefile containing a .suffixes
  1027. directive that tells MAKE to look for a source file (MYPROG.EXE) first
  1028. with an .ASM extension, next with a .C extension, and finally with a
  1029. .CPP extension. If MAKE finds MYPROG.ASM, it builds MYPROG.OBJ from
  1030. the assembler file by calling TASM. MAKE then calls TLINK; otherwise,
  1031. MAKE searches for MYPROG.C to build the .OBJ file, and so on.
  1032.  
  1033.   .suffixes: .asm .c .cpp
  1034.  
  1035.   myprog.exe: myprog.obj
  1036.   tlink myprog.obj
  1037.  
  1038.   .cpp.obj:
  1039.     bcc -P $<
  1040.   .asm.obj:
  1041.     tasm /mx $<
  1042.   .c.obj:
  1043.     bcc -P- $<
  1044.  
  1045.  
  1046. !undef
  1047. ------
  1048. The syntax of the !undef directive is:
  1049.  
  1050.   !undef MacroName
  1051.  
  1052. !undef (undefine) clears the given macro, MacroName, causing an !ifdef
  1053. MacroName test to fail.
  1054.  
  1055.  
  1056. Using macros in directives
  1057. --------------------------
  1058. The macro $d is used with the !if conditional directive to perform
  1059. some processing if a specific macro is defined. The $d is followed by
  1060. a macro name, enclosed in parentheses or braces, as shown in the
  1061. following example.
  1062.  
  1063.   !if $d(DEBUG)                #If DEBUG is defined,
  1064.   bcc -v f1.cpp f2.cpp         #compile with debug information;
  1065.   !else                        #otherwise (else)
  1066.   bcc -v- f1.cpp f2.cpp        #don't include debug information.
  1067.   !endif
  1068.  
  1069. Don't use the $d macro when MAKE is invoked with the -N option.
  1070.  
  1071. /**************************** END OF FILE ********************************/
  1072.  
  1073.